Skip to content

Load Composer's autoloader when installed as a dependency - #879

Merged
Firehed merged 1 commit into
mainfrom
723/dependency-autoloader
Oct 28, 2026
Merged

Firehed merged 1 commit into
mainfrom
723/dependency-autoloader

Conversation

@Firehed

@Firehed Firehed commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Closes #723.

When the package is installed as a dependency, bin/php-lsp runs from vendor/firehed/php-lsp/bin/, and its hard-coded ../vendor/autoload.php does not exist there, so the server fails before it starts.

For a PHP executable a package declares, Composer's vendor/bin launcher sets $GLOBALS['_composer_autoload_path'] to the project's autoloader before running it (see Composer\Installer\BinaryInstaller::generateUnixyProxyCode; Windows launchers run the same PHP launcher). The executable now uses that path when it is set, and falls back to its own ../vendor/autoload.php when run directly, as in this checkout and the end-to-end tests. PHPUnit's executable does the same.

Testing

The root-project route is covered by the existing end-to-end tests, which start bin/php-lsp directly.

The dependency route has no automated test; #878 tracks adding one in CI. It was verified by hand: a scratch project required this branch through a Composer path repository (copied, not symlinked), with the copied package's own vendor/ moved aside, as a published package would have none. vendor/bin/php-lsp answered initialize with the fix, and failed on the missing vendor/autoload.php with the old line restored.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Firehed
Firehed marked this pull request as ready for review October 28, 2026 19:37
@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.64%. Comparing base (1a778ad) to head (5121d19).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##               main     #879   +/-   ##
=========================================
  Coverage     99.64%   99.64%           
  Complexity     1969     1969           
=========================================
  Files           145      145           
  Lines          4513     4513           
=========================================
  Hits           4497     4497           
  Misses           16       16           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@Firehed
Firehed merged commit 380065b into main Oct 28, 2026
8 checks passed
@Firehed
Firehed deleted the 723/dependency-autoloader branch October 28, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Installing as a dependency must find Composer's autoloader

1 participant